package cn.elwy.rcp.ui.wizard;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.wizard.WizardPage;

/**
 * 向导页父类，所有自定义向导都需要继续此类
 * 
 * @author huangsq
 * @version 1.0, 2013-11-20
 * @since 1.0, 2013-11-20
 */
public abstract class BaseWizardPage extends WizardPage {

  /** 下一步跳转到的页面 */
  protected BaseWizardPage nextPage;
  protected boolean ignoreValidate;

  /**
   * @wbp.parser.constructor
   */
  public BaseWizardPage(String pageName) {
    super(pageName);
  }

  public BaseWizardPage(String pageName, String title, ImageDescriptor titleImage) {
    super(pageName, title, titleImage);
  }

  public void reset() {
  }

  public Object getPageData() {
    return null;
  }

  public boolean validatePage() {
    if (ignoreValidate) {
      return true;
    } else {
      return validate();
    }
  }

  protected boolean validate() {
    return true;
  }

  public boolean backButtonPressed() {
    return true;
  }

  public boolean closePressed() {
    return true;
  }

  public boolean finishButtonPressed() {
    return validatePage();
  }

  public boolean nextButtonPressed() {
    return validatePage();
  }

  @Override
  public BaseWizardPage getNextPage() {
    if (nextPage == null) {
      return (BaseWizardPage) super.getNextPage();
    } else {
      return (BaseWizardPage) nextPage;
    }
  }

  public void setNextPage(BaseWizardPage nextPage) {
    this.nextPage = nextPage;
  }

}
